/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.geek.tutorial.itext.text;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Chunk;
import com.lowagie.text.Font;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Phrase;
import java.io.*;
import java.awt.Color;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfPTable;
import java.util.LinkedList;

/**
 *
 * @author usuario
 */
public class relacionDeGastos {
    public ByteArrayOutputStream relacionDeGastos(LinkedList<String[]> lista, String[] str) throws Exception {
	
		Document document = new Document();
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
		PdfWriter.getInstance(document, buffer);
                document.setPageSize(PageSize.LETTER.rotate());
		document.open();
                
          //      document.add(new Paragraph("Simple Image"));
	//	com.lowagie.text.Image image = com.lowagie.text.Image.getInstance("logoBPDEX.jpg");                
	//	document.add(image);
                Font font = new Font(Font.TIMES_ROMAN, 16, Font.BOLD);
		font.setColor(new Color(0x00, 0x00, 0x00));
		Chunk chunk = new Chunk("                   RELACIÓN DE GASTOS BANCO DE PROYECTOS\n", font);				
		Phrase phrase = new Phrase(30, ""); 
		phrase.add(chunk);                
		Paragraph para = new Paragraph();
                para.add(phrase);
                document.add(para);
                Font negrita = new Font(Font.TIMES_ROMAN, 12, Font.BOLD);
		negrita.setColor(new Color(0x00, 0x00, 0x00));
                document.add(new Paragraph("\n"));
                Font normal = new Font(Font.TIMES_ROMAN, 12, Font.NORMAL);
		normal.setColor(new Color(0x00, 0x00, 0x00));
                Font subrayada = new Font(Font.TIMES_ROMAN, 12, Font.UNDERLINE);
		subrayada.setColor(new Color(0x00, 0x00, 0x00));
                Font cursiva = new Font(Font.TIMES_ROMAN, 12, Font.ITALIC);
		cursiva.setColor(new Color(0x00, 0x00, 0x00));                
                
                Chunk chunk2 = new Chunk("\n\n");
                String[] sub = lista.get(0);
                
                chunk = new Chunk("Saldo actual: ", negrita);
		document.add(chunk);
                document.add(new Chunk(sub[1],normal));
                chunk = new Chunk("          Mes: ", normal);
		phrase.add(chunk);
                document.add(chunk);
                if (sub[0].equals("1"))
                    sub[0] = "Enero";
                else if (sub[0].equals("2"))
                    sub[0] = "Febrero";
                else if (sub[0].equals("3"))
                    sub[0] = "Marzo";
                else if (sub[0].equals("4"))
                    sub[0] = "Abril";
                else if (sub[0].equals("5"))
                    sub[0] = "Mayo";
                else if (sub[0].equals("6"))
                    sub[0] = "Junio";
                else if (sub[0].equals("7"))
                    sub[0] = "Julio";
                else if (sub[0].equals("8"))
                    sub[0] = "Agosto";
                else if (sub[0].equals("9"))
                    sub[0] = "Septiembre";
                else if (sub[0].equals("10"))
                    sub[0] = "Octubre";
                else if (sub[0].equals("11"))
                    sub[0] = "Noviembre";
                else if (sub[0].equals("12"))
                    sub[0] = "Diciembre";
                chunk = new Chunk(sub[0], normal);
                document.add(chunk);
                
                document.add(chunk2);
                
                PdfPTable table = new PdfPTable(1);
                chunk = new Chunk("GASTOS EFECTUADOS EN EL MES", negrita);
                phrase = new Phrase(30, ""); 
		phrase.add(chunk);                
		table.addCell(phrase);	
		document.add(table);                                
                table = new PdfPTable(7);                
                chunk = new Chunk("FECHA EMISIIÓN CHEQUE", normal);
                phrase = new Phrase(30, ""); 
		phrase.add(chunk);
		table.addCell(phrase);	                
                chunk = new Chunk("N° FACTURA Ó CHEQUE N/D", normal);
                phrase = new Phrase(30, ""); 
		phrase.add(chunk);                
		table.addCell(phrase);
                chunk = new Chunk("CONCEPTO", normal);
                phrase = new Phrase(30, ""); 
		phrase.add(chunk);                
		table.addCell(phrase);
                chunk = new Chunk("BENEFICIARIO", normal);
                phrase = new Phrase(30, ""); 
		phrase.add(chunk);                
		table.addCell(phrase);
                chunk = new Chunk("RIF O CI", normal);
                phrase = new Phrase(30, ""); 
		phrase.add(chunk);                
		table.addCell(phrase);
                chunk = new Chunk("TOTAL FACTURA", normal);
                phrase = new Phrase(30, ""); 
		phrase.add(chunk);                
		table.addCell(phrase);
                chunk = new Chunk("NETO PAGADO", normal);
                phrase = new Phrase(30, ""); 
		phrase.add(chunk);                
		table.addCell(phrase);
                
                int i;
                for(i=0;i<lista.size();i++)
                {   
                    String[] sub2 = lista.get(i);
                    chunk = new Chunk(sub2[4], normal);
                    phrase = new Phrase(30, ""); 
                    phrase.add(chunk);                
                    table.addCell(phrase);                    
                    chunk = new Chunk(sub2[5], normal);
                    phrase = new Phrase(30, ""); 
                    phrase.add(chunk);                
                    table.addCell(phrase);
                    chunk = new Chunk(sub2[6], normal);
                    phrase = new Phrase(30, ""); 
                    phrase.add(chunk);                
                    table.addCell(phrase);
                    chunk = new Chunk(sub2[7], normal);
                    phrase = new Phrase(30, ""); 
                    phrase.add(chunk);                
                    table.addCell(phrase);
                    chunk = new Chunk(sub2[8], normal);
                    phrase = new Phrase(30, ""); 
                    phrase.add(chunk);                
                    table.addCell(phrase);
                    chunk = new Chunk(sub2[9], normal);
                    phrase = new Phrase(30, ""); 
                    phrase.add(chunk);                
                    table.addCell(phrase);
                    chunk = new Chunk(sub2[3], normal);
                    phrase = new Phrase(30, ""); 
                    phrase.add(chunk);                
                    table.addCell(phrase);
                }
                
                document.add(table);
                
                document.add(chunk2);
                chunk = new Chunk("Observaciones: ", negrita);
                document.add(chunk);
                chunk = new Chunk(sub[2], negrita);
                document.add(chunk);
                                                    
                document.add(chunk2);                
                if (str[0].equals("asocciviles") || str[0].equals("benefactores")
                        || str[0].equals("comunidades"))
                {
                    chunk = new Chunk("Nombre del Responsable del Proyecto: ", negrita);
                    document.add(chunk);
                    chunk = new Chunk(str[2], negrita);
                    document.add(chunk);
                    document.add(chunk2);
                    chunk = new Chunk("RIF: ", negrita);
                    document.add(chunk);
                    chunk = new Chunk(str[3], negrita);
                    document.add(chunk);
                }
                else
                {
                    chunk = new Chunk("Nombre del Responsable del Proyecto: ", negrita);
                    document.add(chunk);
                    chunk = new Chunk(str[2] +" "+str[3], negrita);
                    document.add(chunk);
                    document.add(chunk2);
                    chunk = new Chunk("CI: ", negrita);
                    document.add(chunk);
                    chunk = new Chunk(str[4], negrita);
                    document.add(chunk);
                }
                document.close();
                
                return buffer;                                                
    } 
}

